package com.woniu.servicepassengeruser.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.woniu.servicepassengeruser.mapper.PassengerUserMapper;
import com.woniu.servicepassengeruser.service.UserService;
import com.woniu.internalcommon.dto.PassengerUser;
import com.woniu.internalcommon.dto.ResponseResult;
import com.woniu.internalcommon.dto.VerificationCodeDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class UserController {

    @Autowired
    private UserService userService;
    @Autowired
    private PassengerUserMapper passengerUserMapper;
    @PostMapping("/user")
    public ResponseResult loginOrRegister(@RequestBody VerificationCodeDTO verificationCodeDTO){
        String passengerPhone = verificationCodeDTO.getPassengerPhone();
//        System.out.println("手机号："+passengerPhone);
        return userService.loginOrRegister(passengerPhone);
    }
    @GetMapping("/user/{phone}")
    public ResponseResult getUser(@PathVariable("phone") String passengerPhone){
        System.out.println("service-passenger-user: phone:"+passengerPhone);
        return userService.getUserByPhone(passengerPhone);
    }
    @PostMapping("/passenger/register")
    public ResponseResult registerPassenger(@RequestParam("passengerName") String passengerName, @RequestParam("passengerPhone")String passengerPhone, @RequestParam("passengerGender")Byte passengerGender){
        return userService.userRegister(passengerName, passengerPhone, passengerGender);
    }
    @PostMapping("/register")
    public ResponseResult typeRegisterInfom(@RequestBody PassengerUser passengerUser ){
//        PassengerUser passengerUser = new PassengerUser();
        if (passengerUser == null) {
            return ResponseResult.fail(500,"填写错误信息");
        }
        String passengerName;String passengerPhone;Byte passengerGender;
        passengerName=passengerUser.getPassengerName();
        passengerPhone=passengerUser.getPassengerPhone();
        passengerGender= passengerUser.getPassengerGender();
        userService.userRegister(passengerName,passengerPhone,passengerGender);
//            passengerUserMapper.insert(passengerUser);
        return  userService.userRegister(passengerName,passengerPhone,passengerGender);
    }
    @PostMapping("userexist")
    public ResponseResult requeatParam(@RequestParam String passengerPhone){
        return null;
    }

    /**
     * 查询所有用户
     * @return
     */
    @GetMapping("selectAll")
    public ResponseResult<Page<PassengerUser>> selectAll(@RequestParam("current") Integer  current,@RequestParam("size") Integer size ) {
        return userService.selectAll( current, size);
    }
}